package com.vf.admin.platform.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.platform.entity.BaoMing;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Repository
public class BaoMingDao extends BaseDao<BaoMing> {
    /**
     * 保存或者更新
     */
    public void saveOrUpdate(BaoMing baoMing){
        if(baoMing.getId() != null){
            this.update(baoMing);
        }else{
            this.add(baoMing);
        }
    }
    //详情
    public BaoMing get(Integer id){
        return this.get(id,BaoMing.class);
    }

    //列表查询
    public List<BaoMing> findList(Map<String,Object> paraMap){
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("");
        sbStr.append("select * from tbaoming  where 1=1");
        if(StringEx.isNotNull(paraMap.get("xingming"))){
            sbStr.append(" and xingming like ? ");
            paramList.add("%"+paraMap.get("xingming")+"%");
        }
        String sql = sbStr.toString();
        return this.queryList(sql,paramList,BaoMing.class);
    }


    /**
     * 删除
     */
    public void del(int id){
        if (id <= 0) {
            return;
        }
        String sql = "delete  from tbaoming  where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }
}
